package com.itheima.Test;

import java.util.Arrays;
import java.util.Comparator;

public class Test1 {
    public static void main(String[] args) {
        //创建对象 进行排序
        Girlfriend gf1 = new Girlfriend("xaioshishi", 18, 1.78);
        Girlfriend gf2 = new Girlfriend("xaiodandan", 19, 1.65);
        Girlfriend gf3 = new Girlfriend("xaiohuihui", 18, 1.66);

        //数组存储对象
        Girlfriend[] arr = {gf1, gf2, gf3};

        //利用array.sort 方法进行排序
        Arrays.sort(arr, new Comparator<Girlfriend>() {
            @Override
            public int compare(Girlfriend o1, Girlfriend o2) {
                double tmp = o1.getAge() - o2.getAge();
                tmp = tmp == 0 ? o1.getHeight() - o1.getHeight() : tmp;
                tmp = tmp == 0 ? o1.getName().compareTo(o2.getName()) : tmp;
                if(tmp > 0){
                    return 1;
                }else if(tmp > 0){
                    return -1;
                }else{
                    return 0;
                }
            }
        });

        //输出结果
        System.out.println(Arrays.toString(arr));
    }
}
